<?php

	error_reporting(0);
	session_start();
	error_reporting(1);
	
	if (!$_SESSION['threadId'])
	{
		header("Location: frame.php?page=home");
	}
	$threadId = $_SESSION['threadId'];
	
?>

<html>
	<head>
		<script type="text/javascript" src="javascript/forum_home.js"></script>
		<link rel="stylesheet" type="text/css" href="forum.css" />
	</head>
	
	<body>
		<table>
		<?php
			$site_root = "../";
			require_once ($site_root . "common/PinSQL.obj");
			$pinSQL = new PinSQL();
			$pinSQL2 = new PinSQL();
			$pinSQL->Query("SELECT * FROM forum_posts WHERE thread_id=$threadId ORDER BY date");
			
			
			while ($row = $pinSQL->FetchNextRow())
			{
				?>
				<tr>
					<td>
					<table class="post" cellspacing="2">
						<tr><td>
							<table style="background: rgb(37, 44, 122); width: 120px;" cellspacing="0" cellpadding="0"><tr>
								<td style="text-align: center; padding: 5px;"><img src=<?php
									$username = $pinSQL2->GetUsername($row['user_id']);
									$picurl = $pinSQL2->GetUserdataField($username, "picurl");
									echo "/members/userData/$username/$picurl";
								 	?> width="48" height="48" />
								</td>
								</tr>		
								<tr><td class="mediumThreadText"><?php
								echo $username; ?></td>
								</tr>		
								<tr><td class="smallThreadText">
								<?php if ($row['replyto_id'] > 0)	{
									$replyto = $pinSQL2->getUsername($row['replyto_id']);
									echo "in response to $replyto";
									}	?>
								</td></tr>			
							</table>
						</td>
						<td style="vertical-align: top;">
							<table class="post_body" height="100%" cellspacing="0" cellpadding="4">
								<tr><td width="280"></td>
								<td class="post_date"><?php echo $row['date']; ?></td></tr>
								<tr><td colspan="2"><?php echo $row['message']; ?>
								</td></tr>
								<tr><td></td><td></td></tr>
							</table>
						</td>						
						</tr>
					</table>					
					</td>
				</tr>
				<?php
			}
		?>
		</table>
	</body>
</html>